package com.igelato.utils;

import com.igelato.model.User;
import lombok.extern.slf4j.Slf4j;

/**
 * @Description: 线程共享内存
 * @Author: wht
 * @Date: 2024-01-24
 */


@Slf4j
public class ThreadLocalTool {

    // token
    private static final ThreadLocal<String> CONTEXT_token = new ThreadLocal<>();

    public static String getToken() {
        return CONTEXT_token.get();
    }

    public static void setToken(String token) {
        CONTEXT_token.set(token);
    }

    //    user_id
    private static final ThreadLocal<Integer> CONTEXT_user_id = new ThreadLocal<>();

    public static Integer getUserId() {
        return CONTEXT_user_id.get();
    }

    public static void setUserId(Integer user_id) {
        CONTEXT_user_id.set(user_id);
    }

    // 当前时间
    private static final ThreadLocal<Long> CONTEXT_time = new ThreadLocal<>();

    public static Long getTime() {
        return CONTEXT_time.get();
    }

    public static void setCurrentTime() {
        CONTEXT_time.set(System.currentTimeMillis());
    }

    public static void remove() {
        CONTEXT_token.remove();
        CONTEXT_user_id.remove();
        CONTEXT_time.remove();
    }
}

